package main

import (
	"fmt"
	"time"
)

var list []string

func main() {
	start := time.Now()
	n := 6

	gen(0, 0, n, "")

	for _, s := range list {
		fmt.Println(s)
	}

	fmt.Println(time.Now().Sub(start))
}

const (
	l = "("
	r = ")"
)

func gen(left, right, n int, str string) {
	if right == n && left == n {
		list = append(list, str)
		return
	}

	if left < n {
		gen(left+1, right, n, str+l)
	}

	if right < n && left > right {
		gen(left, right+1, n, str+r)
	}
}
